package com.situ.spring.util;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.situ.spring.controller.BanjiController;
import com.situ.spring.controller.CourseController;
import com.situ.spring.controller.StudentController;
import com.situ.spring.entity.Student;

public class SpringTest {

	@Test
	public void test1() {
		// 自己去new这个对象就叫控制正转
		Student student = new Student();
	}
	
	@Test
	public void test2() {
		// 得到Spring容器，当加载Spring容器时候，
		//在xml中配置的bean都会new出对象并放在Spring容器中
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("applicationContext.xml");
		// 从Spring容器中根据名字取出指定的new出来的对象
		Student student = (Student)context.getBean("student");
		System.out.println(student);
	}
	
	@Test
	public void test3() {
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("applicationContext.xml");
		Student student = (Student)context.getBean("student");
		System.out.println(student);
	}
	
	@Test
	public void test4() {
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("applicationContext.xml");
		Student student1 = (Student) context.getBean("student");
		Student student2 = (Student) context.getBean("student");
		System.out.println(student1 == student2);// true
	}
	
	@Test
	public void test5() {
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("applicationContext.xml");
		StudentController studentController = (StudentController) context.getBean("studentController");
		studentController.findAll();
	}
	
	@Test
	public void test6() {
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("applicationContext.xml");
		CourseController courseController = (CourseController) context.getBean("courseController");
		courseController.findAll();
	}
	
	@Test
	public void test7() {
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("applicationContext.xml");
		BanjiController banjiController = (BanjiController) context.getBean("banjiController");
		banjiController.findAll();
	}
	
}
